package com.example.shopspring.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.shopspring.common.ResultData;
import com.example.shopspring.common.ReturnCode;
import com.example.shopspring.entity.ImageClass;
import com.example.shopspring.mapper.ImageClassMapper;
import com.example.shopspring.service.ImageClassService;
import org.springframework.stereotype.Service;

@Service
public class ImageClassServiceImpl extends
        ServiceImpl<ImageClassMapper, ImageClass> implements ImageClassService {
    @Override
    public ResultData getImageClassList(int current, int size) {
        // 创建分页对象，current为当前页码，size为每页显示的数量
        Page<ImageClass> page = new Page<>(current, size);
        LambdaQueryWrapper<ImageClass> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ImageClass::getStatus, 0)
                .orderByAsc(ImageClass::getClassOrder);
        Page<ImageClass> imageClassPage = baseMapper.selectPage(page, queryWrapper);
        return ResultData.success(imageClassPage);
    }

    @Override
    public ResultData saveOrUpdateClass(ImageClass imageClass) {
        boolean b = saveOrUpdate(imageClass);
        if (b)
            return ResultData.success();
        else
            return ResultData.error(ReturnCode.SYSTEM_ERROR.getCode(),"保存或修改失败");
    }
}
